package ge.devfest.hackathon.gg;

import ge.devfest.hackathon.gg.model.Activity;
import ge.devfest.hackathon.gg.model.Activity.Status;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class ActivityDetailsFragment extends BaseActivityFragment {
	private View mContentView;
	private int mActivityId;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		mActivityId = getActivity().getIntent().getIntExtra(BaseActivity.SAVED_OBJECT_ID, -17);
		if(mActivityId != -17)
			mContentView = inflater.inflate(R.layout.activity_activity_preview_details, null);
		else
			mContentView = inflater.inflate(R.layout.activity_activity_edit_details, null);
		return mContentView;
	}
	
	@Override
	public void initContentView(Activity activity, Bundle savedInstanceState) {
		Spinner statusSpinner = (Spinner) mContentView.findViewById(R.id.sp_status);
		String[] statuses = getResources().getStringArray(R.array.drawer_items);
		ArrayAdapter<String> statusAdapter = new ArrayAdapter<String>(getActivity(),
				android.R.layout.simple_list_item_1, statuses);
		statusSpinner.setAdapter(statusAdapter);
		// noop
	}

	@Override
	public void saveActivity(Activity activity) {
		TextView titleTextView = (TextView) mContentView.findViewById(R.id.et_activity_title);
		Spinner statusSpinner = (Spinner) mContentView.findViewById(R.id.sp_status);
		activity.setTitle(titleTextView.getText().toString());
		int statusOrdinal = statusSpinner.getSelectedItemPosition();
		activity.setStatus(Status.values()[statusOrdinal]);
	}
	
}
